package cn.iocoder.yudao.module.acm.dal.mysql.textileproduceplan;

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.acm.controller.admin.textileproduceplan.vo.TextileProducePlanPageReqVO;
import cn.iocoder.yudao.module.acm.dal.dataobject.textileproduceplan.TextileProducePlanDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalTime;

/**
 * 航机管理-纺织品生产计划 Mapper
 *
 * @author yisl
 */
@Mapper
public interface TextileProducePlanMapper extends BaseMapperX<TextileProducePlanDO> {

    default PageResult<TextileProducePlanDO> selectPage(TextileProducePlanPageReqVO reqVO) {
        LambdaQueryWrapperX<TextileProducePlanDO> wrapperX = new LambdaQueryWrapperX<TextileProducePlanDO>()
                .likeIfPresent(TextileProducePlanDO::getPlanCode, reqVO.getPlanCode())
                .likeIfPresent(TextileProducePlanDO::getFlightNo, reqVO.getFlightNo())
                .eqIfPresent(TextileProducePlanDO::getDepTime, reqVO.getDepTime())
                .eqIfPresent(TextileProducePlanDO::getMarkStatus, reqVO.getMarkStatus())
                .orderByDesc(TextileProducePlanDO::getId);
        if (ObjectUtil.isNotEmpty(reqVO.getSearchType())){
            switch (reqVO.getSearchType()){
                case 1:
                    wrapperX.ge(TextileProducePlanDO::getDepTime, LocalTime.parse("00:00"));
                    wrapperX.le(TextileProducePlanDO::getDepTime, LocalTime.parse("06:00"));
                    break;
                case 2:
                    wrapperX.ge(TextileProducePlanDO::getDepTime, LocalTime.parse("06:00"));
                    wrapperX.le(TextileProducePlanDO::getDepTime, LocalTime.parse("12:00"));
                    break;
                case 3:
                    wrapperX.ge(TextileProducePlanDO::getDepTime, LocalTime.parse("12:00"));
                    wrapperX.le(TextileProducePlanDO::getDepTime, LocalTime.parse("18:00"));
                    break;
                case 4:
                    wrapperX.ge(TextileProducePlanDO::getDepTime, LocalTime.parse("18:00"));
                    wrapperX.le(TextileProducePlanDO::getDepTime, LocalTime.parse("23:59:59"));
                    break;
            }
        }
        return selectPage(reqVO, wrapperX);
    }

}